package logic

import (
	"context"
	"fmt"
	"house_srv/model/mysql"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddHouseLogic {
	return &AddHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddHouseLogic) AddHouse(in *house.AddHouseRequest) (*house.AddHouseResponse, error) {
	// todo: add your logic here and delete this line
	h := mysql.House{
		HouseTitle:   in.HouseTitle,
		HouseAddress: in.HouseAddress,
		HouseIntro:   in.HouseIntro,
		HousePrice:   float64(in.HousePrice),
	}
	err := h.Create()
	if err != nil {
		return nil, fmt.Errorf("发布失败")
	}
	return &house.AddHouseResponse{Id: int64(h.ID)}, nil
}
